package com.spa.interfaces.common;

import com.spa.application.query.FileQuery;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.infrastructure.service.storage.FileService;
import com.spa.infrastructure.service.storage.StorageType;
import com.spa.interfaces.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("file")
public class FileController extends BaseController {

    @Resource
    private FileService fileService;

    @PostMapping("getUrl")
    public ResponseMessage<String> getUrl(@RequestBody FileQuery query) throws IOException {
        return responseHelper.success(fileService.getUrl(query.getKey(), StorageType.QINIUYUN));
    }

    @PostMapping("getUploadToken")
    public ResponseMessage<String> getUploadToken() throws IOException {
        return responseHelper.success(fileService.getUploadToken());
    }

}
